# AVR-GCC Makefile
PROJECT=Motor_Control
MAIN=main
CC=avr-gcc
OBJCOPY=avr-objcopy
MMCU=atmega328p
TARGET=m328p
BOARD=arduino
INC=../Inc/

CFLAGS=-mmcu=$(MMCU) -Wall
#Link and hex convert
$(PROJECT).hex: $(PROJECT).out
	$(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex

$(PROJECT).out : main.o uart.o
	$(CC) $(CFLAGS) -o $(PROJECT).out buildDir/main.o buildDir/uart.o

#build main
main.o: buildDir Src/main.c 
	$(CC) $(CFLAGS) -o buildDir/main.o -c Src/main.c

#build uart
uart.o: buildDir Src/L0/L0_src/uart.c Src/L0/L0_inc/uart.h
	$(CC) $(CFLAGS) -o buildDir/uart.o -c Src/L0/L0_src/uart.c

#Dossier poubelle
buildDir : 
	mkdir buildDir

#prorammation carte
program: $(PROJECT).hex
	avrdude -p $(TARGET) -c $(BOARD) -P /dev/ttyUSB0 -b 57600 -F -U flash:w:$(PROJECT).hex

#nettoyage
clean:
	rm -f $(PROJECT).out
	rm -f $(PROJECT).hex

#nettoyage profond
erase:
	#rm buildDir/*.o
	rm -r buildDir


